<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Title</title>
	<!-- baidu map -->
	<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
	<style type="text/css">
		body, html,#allmap {width: 100%;height: 100%;overflow: hidden;margin:0;font-family:"微软雅黑";}
	</style>
	<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=DezNcsGYMqUvMpB3d1DKlvejwHTtwIDo"></script>
</head>
<body>
	<div id = "allmap" ></div>

</body>
</html>


<script type="text/javascript">
    //百度地图API功能
    var map = new BMap.Map("allmap");
    map.centerAndZoom("江苏盐城",15);//根据坐标初始化地图
    map.enableScrollWheelZoom(true);
    map.addControl(new BMap.NavigationControl()); //平移缩放控件
    map.addControl(new BMap.ScaleControl()); //比例尺
    map.addControl(new BMap.OverviewMapControl()); //缩略地图
    map.addControl(new BMap.MapTypeControl()); //地图类型
    map.setCurrentCity("江苏盐城"); // 仅当设置城市信息时，MapTypeControl的切换功能才能可用
    //添加标注


    var geolocation = new BMap.Geolocation();
    geolocation.getCurrentPosition(function(r){
        if(this.getStatus() == BMAP_STATUS_SUCCESS){
            var mk = new BMap.Marker(r.point);
            map.addOverlay(mk);
            map.panTo(r.point);
            alert('您的位置：'+r.point.lng+','+r.point.lat);
        }
        else {
            alert('failed'+this.getStatus());
        }
    },{enableHighAccuracy: true})

    // var marker = new BMap.Marker(new BMap.Point(r.point.lng,r.point.lat)); // 创建标注
    // map.addOverlay(marker); // 将标注添加到地图中

    var geoc = new BMap.Geocoder();
    map.addEventListener("click", function(e){
        var pt = e.point;
        geoc.getLocation(pt, function(rs){
            var addComp = rs.addressComponents;
            alert(addComp.province + ", " + addComp.city + ", " + addComp.district + ", " + addComp.street + ", " + addComp.streetNumber);
        });
    });
</script>